package com.leo;

import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

/**
 * @ClassName CollectionBindingDemo
 * @Description 集合绑定：双向绑定
 * @Author wangss
 * @date 2020.05.31 21:56
 * @Version 1.0
 */
public class CollectionBinding4Demo {

    public static void main(String[] args) {

        ObservableList<String> list1 = FXCollections.observableArrayList();
        SimpleListProperty<String> slp1 = new SimpleListProperty<>(list1);
        slp1.add("A");
        slp1.add("B");

        ObservableList<String> list2 = FXCollections.observableArrayList();
        SimpleListProperty<String> slp2 = new SimpleListProperty<>(list2);
        slp2.add("C");
        slp2.add("D");

        System.out.println("slp1 = " + slp1.getValue() + " | " + "slp2 = " + slp2.getValue());

        slp1.bindContentBidirectional(slp2);

        System.out.println("slp1 = " + slp1.getValue() + " | " + "slp2 = " + slp2.getValue());

        slp1.add("E");

        slp2.add("F");

        System.out.println("slp1 = " + slp1.getValue() + " | " + "slp2 = " + slp2.getValue());

        System.out.println("list1 = " + list1 + " | " + "list2 = " + list2);

        slp2.sort((item1, item2) -> item2.compareTo(item1));

        System.out.println("slp1 = " + slp1.getValue() + " | " + "slp2 = " + slp2.getValue());

        System.out.println("list1 = " + list1 + " | " + "list2 = " + list2);
    }
}
